<?php

namespace App\Models\Api;

use App\Tools\Financial;
use App\Tools\Prstatic;

use Illuminate\Database\Eloquent\Model;

class StoreGoodsRepertoryLog extends Model
{

    protected $table = 'store_goods_repertory_log';
    protected $primaryKey = 'id';
    protected $dateFormat = 'U';
    protected $casts = [
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s'
    ];

    /**
     * 获取列表
     * @param $store_id
     * @param int $type
     * @param int $limit
     */
    public static function getList($store_id, $type = 0, $limit = 10)
    {
        $db = self::from('store_goods_repertory_log as sg')
            ->select(['g.id', 'g.goods_sn', 'g.goods_img', 'g.goods_name', 'sg.goods_num', 'c.cate_name', 'sg.remark', 'sg.type', 'sg.create_user', 'sg.created_at'])
            ->leftJoin('goods as g', 'g.id', '=', 'sg.goods_id')
            ->leftJoin('goods_category as c', 'c.id', '=', 'g.cate_id')
            ->where(['sg.store_id' => $store_id]);
        if ($type == 1) {
            $db->where(['sg.type' => 1]);
        } elseif ($type == 2) {
            $db->where(['sg.type' => 2]);
        }
        $list = $db->orderBy('sg.id', 'desc')->paginate($limit);
        return $list;
    }

}
